package pkg

import (
	"fmt"
	"github.com/smartwalle/alipay/v3"
)

func Alipay(orderSn string, amount string) string {
	var privateKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAurVL9QGDkrmrE8IA1xUY/5IlxIwLKgkZwiJTR2Y4UWZWok4CTjfe0cS4/PCXz540B5m+v+xcgX+hB9yVidImxmqRaIZXVAlU+S0hjKE0StjIlCGCoglV7G7Lg/gWafwmV5L5k+zcFqNCH9c1hoQM0IsxXuzTky0EM7LV+4esRqkJ5peZaWUHTN4Xf6nH5MQc1d5p/gdWwHFMOTQsozZHsO2iWTFIvttvS4GAHe1sW5890/sVHMbYr1pcsEo4Ns6mbaTAS4uihFQfERbfVZV7bIUmoUMCbzH7VwTKqjNeCEKJh4fyDMuejZT7naEzefQ4UnSSJFTpQlEWK3Bo9EFehQIDAQAB" // 必须，上一步中使用 RSA签名验签工具 生成的私钥
	appId := "9021000140611092"
	var client, err = alipay.New(appId, privateKey, false)
	if err != nil {
		fmt.Println(err)
		return ""
	}

	var p = alipay.TradeWapPay{}
	p.NotifyURL = "http://xxx"
	p.ReturnURL = "https://go.dev/"
	p.Subject = "商品支付"
	p.OutTradeNo = orderSn
	p.TotalAmount = amount
	p.ProductCode = "QUICK_WAP_WAY"

	url, err := client.TradeWapPay(p)
	if err != nil {
		fmt.Println(err)
		return ""
	}
	// 这个 payURL 即是用于打开支付宝支付页面的 URL，可将输出的内容复制，到浏览器中访问该 URL 即可打开支付页面。
	var payURL = url.String()
	fmt.Println(payURL)
	return payURL
}
